var gulp = require('gulp');
var server = require('gulp-connect');
var gulpSequence = require('gulp-sequence');

gulp.task('ser',function(){
    return server.server({
        port:7070,
        root:'dist',
        livereload:true
    })
});

gulp.task('copy-html',function(){
    return gulp.src('src/*.html')
    .pipe(gulp.dest('dist'))
    .pipe(server.reload());
});

gulp.task('copy-css',function(){
    return gulp.src('src/public/www/css/*.css')
        .pipe(gulp.dest('dist/public/www/css'))
        .pipe(server.reload());
});

gulp.task('copy-js',function(){
    return gulp.src('src/public/www/js/*.js')
        .pipe(gulp.dest('dist/public/www/js'))
        .pipe(server.reload());
});

gulp.task('dist', gulpSequence(['copy-html', 'copy-css','copy-js']));

gulp.task('copy005www', function() {
    return gulp.src([
            'dist/**'
        ])
        .pipe(gulp.dest('../dist/www'));
});

gulp.task('default',gulpSequence('dist','copy005www'));

gulp.task('serlook',gulpSequence('watch','ser'));

gulp.task('watch',function(){
    gulp.watch('src/*.html',function(){
        gulp.run('copy-html')
    });
    gulp.watch('src/public/www/css/*.css',function(){
        gulp.run('copy-css')
    })
});


